package com.face.server.service;

import com.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by ryan on 2018/4/2.
 */
@Component
public class ScheduleService {
    @Autowired
    private AdminStuService stuService;

    private static final Logger logger = LoggerFactory.getLogger(ScheduleService.class);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Scheduled(cron = "0 0/5 * * * ?")
    public void scheduleDelete() throws ParseException {
        Date date=DateUtils.getToday();
        String tmp=sdf.format(date);
        Date now=sdf.parse(tmp);
        logger.info("the judging time---"+now.toString());
        logger.info("the scan is starting");
        int i=stuService.deleteByEffectDate(now);
        if (i==0)
            logger.info("无无效学生");
        else
            logger.info("有无效学生");
    }
}
